<template>
  <div class="container">
    <h2 class="handle-title">系统管理 > 用户管理</h2>
    <div class="handle-box">
      <div>
        <span class="search-label" style="margin-left: 5px">用户名:</span>
        <el-input v-model="username" style="width: 120px" placeholder="请输入用户名字"></el-input>
        <span class="search-label" style="margin-left: 5px">姓名或昵称:</span>
        <el-input v-model="name" style="width: 120px" placeholder="请输入用户姓名或昵称"></el-input>
        <span class="search-label" style="margin-left: 5px">用户电话:</span>
        <el-input v-model="phone" style="width: 120px" placeholder="请输入用户电话"></el-input>
        <span class="search-label" style="margin-left: 5px">用户状态:</span>
        <el-select v-model="value" style="width: 120px">
          <el-option
            v-for="item in options"
            :key="item.value"
            :label="item.label"
            :value="item.value">
          </el-option>
        </el-select>
        <el-button class="query_btn" type="primary" @click="goSearch">查询</el-button>
        <el-button class="add_btn" type="primary" @click="addRole">新增</el-button>
      </div>
    </div>
    <el-table
      :data="tableData"
      class="table"
      border>
      <el-table-column prop="username" label="用户名"/>
      <el-table-column prop="usertruename" label="用户姓名"/>
      <el-table-column prop="nickname" label="微信昵称"/>
      <el-table-column prop="userphone" label="电话"/>
      <el-table-column label="机构管理员">
        <template #default="{row}">
          {{ row.orguserid == -1 ? "是" : "否" }}
        </template>
      </el-table-column>

      <el-table-column label="教师">
        <template #default="{row}">
          <el-button v-if="row.isteacher===1" type="text" icon="el-icon-edit-outline">编辑</el-button>
          <el-button v-if="row.isteacher===0||row.isteacher===null" type="text" icon="el-icon-edit-outline">成为教师</el-button>
        </template>
      </el-table-column>

      <el-table-column label="销售">
        <template #default="{row}">
          <el-button icon="el-icon-edit-outline" v-if="row.issaler===1" type="text">编辑</el-button>
          <el-button icon="el-icon-edit-outline" v-if="row.issaler===0||row.issaler===null" type="text">成为销售</el-button>
        </template>
      </el-table-column>
      <el-table-column label="操作" width="200">
        <template #default="{row}">
          <el-button type="text" icon="el-icon-edit-outline" @click="goUpdate(row.roleid)">编辑</el-button>
          <el-button
            type="text"
            icon="el-icon-unlock"
            class="red"
            @click="goRight(row.roleid)">角色
          </el-button>
          <el-button
            type="text"
            @click="goOrder(row.roleid)">创建订单
          </el-button>
        </template>
      </el-table-column>
    </el-table>
    <div class="pagination">
      <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="currentPage"
        :page-sizes="[10, 20, 50]"
        :page-size="pageSize"
        layout="total, sizes, prev, pager, next"
        :total="totalNum">
      </el-pagination>
    </div>
  </div>
</template>

<script>
import {getUserList} from "../../api/public/api";

export default {
  name: "User",
  data() {
    return {
      username: "",
      name: '',
      phone: '',
      value: "-1", //状态选择默认为 -1 表示全部
      options: [
        {
          value: '-1',
          label: '全部'
        },
        {
          value: '1',
          label: '可用'
        },
        {
          value: '0',
          label: '不可用'
        }
      ],
      tableData: [],   //默认数据列表
      currentPage: 1, //默认第一页
      pageSize: 10,   //默认每页10条
      totalNum: 0,    //默认总条数
    }
  },
  mounted() {
    this.userList()
  },
  methods: {
    //每页条数
    handleSizeChange(val) {
      this.pageSize = val;
      this.userList()
    },
    // 第几页
    handleCurrentChange(val) {
      this.currentPage = val;
      this.userList()
    },
    //封装请求方法
    userList() {
      let params = {
        pagenum: this.currentPage,
        pagesize: this.pageSize,
        // rolename:this.search,
        // rolestate:this.value
        username: this.username,
        usertruename: this.name,
        userphone: this.phone,
        userstate:this.value
      };
      getUserList(params).then((res) => {
        // console.log(res)
        // console.log(res.data.pagedata.records[0].isteacher);
        this.tableData = res.data.pagedata.records;
        this.totalNum = res.data.pagedata.total;
      })
    },
    //Search搜索按钮
    goSearch() {
      this.userList()
    },
    //新增角色
    addRole() {
      this.$router.push({
        path: "/demo",
        query: {}
      })
    },
    //修改
    goUpdate(id) {
      // console.log(id)
      this.$router.push({
        path: "/updaterole",
        query: {id}
      })
    },
    //权限管理
    goRight(id) {
      this.$router.push({
        path: "/right",
        query: {id}
      })
    },
    goOrder(id) {

    }
  },
}
</script>

<style>
.handle-title {
  line-height: 50px;
}
</style>

